package com.nothing.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.nothing.dao.UserRepository;
import com.nothing.domain.User;
import com.nothing.service.UserService;

@Service
public class UserServiceImpl extends ServiceImpl<UserRepository, User> implements UserService {

    @Autowired
    private UserRepository userRepository;
    

    @Override
    public boolean authenticate(String username,String password){
        User user = this.findByEmail (username);
        if (user == null) {
            return false;
        } else {
            if (password.equals (user.getPassword ())) return true;
            else return false;
        }
    }

    @Override
    public User findByEmail(String email){
        return userRepository.findByEmail (email);
    }

    @Override
    public void deleteInBatch(List<User> users){ 
        userRepository.deleteBatchIds(users.stream().map(user -> user.getId()).collect(Collectors.toList()));
    }

	@Override
	public User save(User user) {
		userRepository.insert(user);
		return user;
	}

	@Override
	public User update(User user) {
		userRepository.updateById(user);
		return user;
	}

}
